<?php

namespace app\index\controller;
use think\Exception;
use think\facade\Hook;
use think\container;
use think\Db;

class Server
{
    protected $ip;
    protected $port;

    public function __construct($ip,$port)
    {
        $this->ip = $ip;
        $this->port = $port;
    }

    public function on($method, $callback) {

        if(!method_exists(this,$method)) {
            throw new Exception('方法'.$method.'不存在');
        } else {
            return call_user_func([this,$method],$callback);
        }

    }


    public function start($callback) {
        return call_user_func($callback,this);
    }

    // 请求进来
    public function request($callback) {
        $mail = new Mail();
        return call_user_func($callback,this,$mail);
    }

}
